package com.aliyun.oss.service.impl;

import com.aliyun.oss.mapper.UserInfoPicMapper;
import com.aliyun.oss.pojo.UserInfoPic;
import com.aliyun.oss.service.UserInfoPicService;
import com.aliyun.oss.utils.JwtUtil;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserInfoPicServiceImpl implements UserInfoPicService {
    @Autowired
    UserInfoPicMapper userInfoPicMapper;
    @Override
    public UserInfoPic getUserUserInfoPic(String authHeader) {
        Claims claims = JwtUtil.analysisToken(authHeader);
//        System.out.println(claims.get("id"));
        UserInfoPic userInfoPic = userInfoPicMapper.getUserInfo(claims.get("id"));
        return userInfoPic;
    }

    @Override
    public void updateUserInfo(String authHeader, UserInfoPic userInfoPic) {
        Claims claims = JwtUtil.analysisToken(authHeader);
        Integer id = (Integer) claims.get("id");
        System.out.println("这是"+id);
        userInfoPic.setUserId(id);
        userInfoPicMapper.updateUserInfo(userInfoPic);
    }

    @Override
    public void updateUserAvatar(String authHeader, String upload) {
        Claims claims = JwtUtil.analysisToken(authHeader);
        Integer id = (Integer) claims.get("id");
        userInfoPicMapper.updateUserAvatar(id,upload);
    }

    @Override
    public void updateUserPwd(String authHeader, Map<String, Object> pwds) {
        Claims claims = JwtUtil.analysisToken(authHeader);
        Integer id = (Integer) claims.get("id");
        String newPwd= (String) pwds.get("newPwd");
        String oldPwd= (String) pwds.get("oldPwd");
        userInfoPicMapper.updateUserPwd(id,newPwd,oldPwd);
    }


}
